package com.hyst.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.hyst.common.ResultBean;
import com.hyst.common.ResultPage;
import com.hyst.domain.Period;
import com.hyst.service.PeriodService;

/**
 * @Description:上课时间表--保留基础数据controller
 * @author：dy 
 *@Date：2018年08月25日
 */
@RestController
@RequestMapping("periods")
@CrossOrigin(maxAge = 3600, origins = "*")
public class PeriodController {
	@Autowired
	private PeriodService periodService;
	
	@GetMapping
	public ResultPage<Period> getProjects(Period period) {
		return ResultPage.success(periodService.list(period));
	}

	@GetMapping("hidden")
	public ResultBean getHiddenProjects(@RequestParam("teacherId") String teacherId) {
		return periodService.list2(teacherId);
	}

	@PostMapping
	public ResultBean<Period> creat(final Period period) {
		return ResultBean.success(periodService.insert(period));
	}

	/**
	 * 获取教师可用的上课时间表
	 * @param teancherId
	 * @return
	 */
	@GetMapping("/used")
	public ResultPage<Period> getPeriodsUsed(@RequestParam("teacherId") String teancherId) {
		return ResultPage.success(periodService.getPeriodsUsed(teancherId));
	}


	/**
	 * @Description: 根据主键查询
	 * @param id
	 * @return ResultBean<Period>
	 */
	@GetMapping("{id}")
	public ResultBean<Period> getByPriKey(@PathVariable("id") final Integer id) {
		return ResultBean.success(periodService.getByPriKey(id));
	}

	/**
	 * @Description: 根据主键更新全字段
	 * @param period
	 * @return ResultBean<Period>
	 */
	@PatchMapping("{id}")
	public ResultBean<Period> update(final Period period) {
		return ResultBean.success(periodService.update(period));
	}

	/**
	 * @Description: 根据主键更新不为默认值的字段
	 * @param period
	 * @return ResultBean<Period>
	 */
	//@PutMapping("{id}")
	@PostMapping("id")
	public ResultBean<Period> updatePatch(@PathVariable("id") final Integer id,
			final Period period) {
		return ResultBean.success(periodService.updateSelective(period));
	}

	/**
	 * @Description: 根据主键删除
	 * @param id
	 * @return ResultBean<Period>
	 */
	@DeleteMapping("{id}")
	public ResultBean<Period> delete(@PathVariable("id") final Integer id) {
		return ResultBean.success(periodService.delete(id));
	}


}
